export default {
  install(Vue) {
    Vue.mixin({
      inject: ["reload"],
      data() {
        return {
        }
      },
      mounted() {},
      methods: {
        formValidate(formName = 'form'){
          return new Promise((reslove,reject)=>{
            this.$refs[formName].validate((valid,object) => {
              if(valid){
                reslove()
              }else{
                for (let key in object) {
                    let element = object[key];
                    this.$message.error(element[0].message)
                }
                reject()
              }
            })
          })
        },
        downloadBlob(response) {
          let blob = new Blob([response.data], {
            type: response.data.type
          });
          if (window.navigator && window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveOrOpenBlob(blob, response.fileName);
          } else {
            var downloadElement = document.createElement("a");
            var href = window.URL.createObjectURL(blob); // 创建下载的链接
            downloadElement.href = href;
            downloadElement.download = response.fileName; // 下载后文件名
            document.body.appendChild(downloadElement);
            downloadElement.click(); // 点击下载
            document.body.removeChild(downloadElement); // 下载完成移除元素
            window.URL.revokeObjectURL(href); // 释放掉 blob 对象
          }
        },
        goBack(type = 'page') {
          this.$router.go(-1)
          if (type == 'route') {
            this.$store.dispatch('deleteCurrentPageTag')
            // this.reload()
          }
        },
      }
    })
  }
}